package com.spring.shops.admin.controller.system;

import com.spring.shops.model.entity.TzArea;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.AreaVO;
import com.spring.shops.service.AreaService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//系统管理->地址管理
@RestController
@RequestMapping("/admin/area")
public class AddressController {
    @Autowired
    private AreaService areaService;
    /**
     * 列出所有的地区
     * @param current
     * @param size
     */
    @GetMapping("/list")
    public ServerResponseEntityVoid<List<AreaVO>> list(Long current, Long size){
        return areaService.list();
    }

    /**
     * 新增数据
     * @param area
     * @return
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody TzArea area){
         return areaService.save(area);
    }

    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ServerResponseEntityVoid deleteById(@PathVariable Long id){
        return areaService.deleteById(id);
    }

    /**
     * 根据id获取信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public ServerResponseEntityVoid<AreaVO> getInfoById(@PathVariable Long id){
        return areaService.getInfoById(id);
    }

    /**
     * 更新数据
     * @param vo
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid updateInfo(@RequestBody AreaVO vo)
    {
        return areaService.updateInfo(vo);
    }
}
